package zyu.qwq.qwq_bungee_plugin;

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.Title;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ServerSwitchEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;

public class PlayerSwitchEvent implements Listener {
    @EventHandler
    public void onServerSwitch(ServerSwitchEvent e){
        ProxiedPlayer p = e.getPlayer();
        String playerName = p.getDisplayName();
//        String fromServerName = e.getFrom().getName();
        String fromServerName = e.getFrom() == null ? "地球online" : e.getFrom().getName();
        String toServerName = p.getServer().getInfo().getName();

        TextComponent msg1 = new TextComponent(playerName);
        msg1.setBold(true);
        msg1.setColor(ChatColor.AQUA);

        TextComponent msg2 = new TextComponent(": [" + fromServerName + "] --> [" + toServerName + "]");
        msg1.setBold(false);
        msg2.setColor(ChatColor.DARK_AQUA);

        msg1.addExtra(msg2);

//        String outputString = playerName + ": [" + fromServerName + "] --> [" + toServerName + "]";
        for (ProxiedPlayer player: ProxyServer.getInstance().getPlayers()){
            player.sendMessage(
                msg1
            );
        }
    }
}
